# -*- coding: utf-8 -*-
from datetime import timedelta
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator
from spmi_dm_composite.time_sensor.time_after_05_15 import time_after_05_15


#Hive表名
hive_table = "dws_composite_sign_dt_input_mt_smry"
#任务名
task_id = f"spmi_dws__{hive_table}"

spmi_dws__dws_composite_sign_dt_input_mt_smry = SparkSqlOperator(
    task_id=f'{task_id}',
    task_concurrency=1,
    pool_slots=1,
    master='yarn',
    name=f'{task_id}_{{{{ execution_date | date_add(1) | cst_ds }}}}',
    sql=f'spmi_dm_composite/dws/{hive_table}/execute.sql',
    retries=0,
    pool='spmi_piece',
    email=['yushuo@jtexpress.com', 'yl_bigdata@yl-scm.com'],
    execution_timeout=timedelta(hours=1),
    yarn_queue='pro',
    driver_memory='2G',
    driver_cores=2,
    executor_cores=2,
    executor_memory='6G',
    num_executors=40,  # spark.dynamicAllocation.enabled 为 True 时，num_executors 表示最少 Executor 数
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors': 50,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 60,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.executor.memoryOverhead': '2G',  # 堆外内存
          'spark.shuffle.consolidateFiles': 'true',
          'spark.sql.shuffle.partitions': 480,
          'spark.sql.adaptive.enabled': 'true',
          'spark.sql.adaptive.shuffle.targetPostShuffleInputSize': 536870912 ,
          'spark.executor.extraJavaOptions': '-XX:+UseG1GC -XX:ParallelGCThreads=2',
           'spark.yarn.maxAppAttempts':0
          },
    hiveconf={'hive.exec.dynamic.partition': 'true',  # 动态分区
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions': 200,
              'hive.exec.max.dynamic.partitions.pernode': 200,
              },
)
spmi_dws__dws_composite_sign_dt_input_mt_smry << time_after_05_15